package com.prothink.controller.statistics;


import com.prothink.entity.CourseSalesVolume;
import com.prothink.service.CourseSalesVolumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *销售课程量控制层
 * @Date 2022 11 24
 */
@CrossOrigin
@RequestMapping("CourseSalesVolume")
@Controller
public class CourseSalesVolumeController {
    @Autowired
    private CourseSalesVolumeService courseSalesVolumeService;

    /**
     * 获取全部销售的课程
     * @param courseSalesVolume 课程销售实体类
     * @return 所有销售的课程
     */
    @ResponseBody
    @RequestMapping("/getCourseSalesVolume")
    public List getCourseSalesVolume(CourseSalesVolume courseSalesVolume){
        return courseSalesVolumeService.getCourseSalesVolume(courseSalesVolume);
    }

    /**
     * 添加被购买的课程信息
     * @param courseSalesVolume 课程销售实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/addCourseSalesVolume")
    public Integer addCourseSalesVolume(CourseSalesVolume courseSalesVolume){
        return courseSalesVolumeService.addCourseSalesVolume(courseSalesVolume);
    }
    /**
     * 获取近7，30，90天被购买的课程信息
     * @param courseSalesVolume 课程销售实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/getBuyCourseSalesVolume")
    public List getBuyCourseSalesVolume(CourseSalesVolume courseSalesVolume){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            courseSalesVolume.setSalesTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return courseSalesVolumeService.getBuyCourseSales(courseSalesVolume);
    }
}
